import { TransformInterceptor } from './core/interceptor/transform.interceptor';
import { HttpExceptionFilter } from './core/filter/http-exception.filter';
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
async function bootstrap() {
  // 使用nest的核心类  NestFactory 下面的静态方法 create 实现一个 INestApplication  对象  创建 appModule 实例
  const app = await NestFactory.create<NestExpressApplication>(AppModule);  
  // app.enableCors() //允许跨域开启
  app.setGlobalPrefix('api'); // 全局路由前缀
  app.useGlobalFilters(new HttpExceptionFilter()); // 全局异常处理过滤器的注册
  app.useGlobalInterceptors(new TransformInterceptor()); // 全局响应成功拦截器的注册

  app.useGlobalPipes(new ValidationPipe());
  // 设置 swagger 文档信息
  const config = new DocumentBuilder()
    .setTitle('汇电官网')
    .setDescription('汇电官网接口文档')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);
  await app.listen(9080);
}
bootstrap();
